package com.tudouji.project.mt.controller;

import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.project.mt.domain.MtShop;
import com.tudouji.project.mt.domain.MtToken;
import com.tudouji.project.mt.service.IMtShopService;
import com.tudouji.project.mt.service.IMtTokenService;
import com.tudouji.project.mt.service.impl.MtPullService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 美团Controller
 * 
 * @author tudouji
 * @date 2024-01-16
 */
@Slf4j
@RestController
@RequestMapping("/mt")
public class MtController extends BaseController
{
    @Autowired
    private MtPullService mtPullService;
    @Autowired
    private IMtShopService iMtShopService;

    /**
     * 拼装授权URL, 获取authorization_code
     */
    @GetMapping(value = "/authURL")
    public AjaxResult authURL()
    {
        return AjaxResult.success(mtPullService.authURL());
    }

    /**
     * 授权authorization_code回调
     * @param code 授权码，有效期为10分钟
     * @param sign 请求的数字签名
     * @param developerId developerId
     * @param businessId 业务类型id
     * @param state ISV自定义字段回传
     */
    @GetMapping(value = "/authURLCallBack")
    public AjaxResult authURLCallBack(@RequestParam String code, @RequestParam(required = false) String sign,@RequestParam(required = false) Long developerId,
                                      @RequestParam(required = false) Integer businessId,@RequestParam(required = false) String state)
    {
        mtPullService.auth(code, sign);
        return AjaxResult.success();
    }

    /**
     * 查询授权资源ID列表
     * @return
     */
    @GetMapping(value = "/authResources")
    public AjaxResult authResources()
    {
        mtPullService.authResources();
        return AjaxResult.success();
    }
}
